package com.rh.bmw4s.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.TextView;

import com.github.jdsjlzx.ItemDecoration.DividerDecoration;
import com.github.jdsjlzx.interfaces.OnItemClickListener;
import com.github.jdsjlzx.recyclerview.LRecyclerView;
import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter;
import com.rh.bmw4s.R;
import com.rh.bmw4s.bean.BrandBean;
import com.rh.bmw4s.bean.ThirdSearchBean;
import com.rh.bmw4s.inter.OpenFinalIner;
import com.rh.bmw4s.inter.OpenItemIner;

import java.util.List;

/**
 * 三级搜索，第三级
 */

public class FianlAdapter extends ListBaseAdapter<ThirdSearchBean.DatasBean.YearsBean> {
    Context context;
    //OpenFinalIner iner;

    public FianlAdapter(Context context) {
        super(context);
        this.context = context;
        // this.iner = (OpenFinalIner)context.getApplicationContext();
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_category;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        ThirdSearchBean.DatasBean.YearsBean yearsBeen = mDataList.get(position);
        LRecyclerView recyclerView = holder.getView(R.id.recyclerView);
        TextView TvTitle = holder.getView(R.id.tv_title);
        TvTitle.setText(yearsBeen.getYear());

        final List<ThirdSearchBean.DatasBean.YearsBean.ListBean> list = yearsBeen.getList();
        if (list == null) {
            return;
        }
        if (!list.isEmpty()) {
            recyclerView.setLayoutManager(new LinearLayoutManager(context));
            FinalItemAdapter mAdapter = new FinalItemAdapter(context);
            mAdapter.setDataList(list);
            LRecyclerViewAdapter lRecyclerViewAdapter = new LRecyclerViewAdapter(mAdapter);
            recyclerView.setAdapter(lRecyclerViewAdapter);
            DividerDecoration divider = new DividerDecoration.Builder(context)
//                    .setHeight(R.dimen.divider_height_1)
                    .setPadding(R.dimen.divider_padding)
                    .setColorResource(R.color.line_1)
                    .build();
            recyclerView.addItemDecoration(divider);
            recyclerView.setLoadMoreEnabled(false);
            recyclerView.setPullRefreshEnabled(false);
            recyclerView.refresh();
            lRecyclerViewAdapter.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    openFinalItemClick.itemFinalItemClick(list.get(position));
                }
            });
        }
    }

    public interface OpenFinalItemClick {
        void itemFinalItemClick(ThirdSearchBean.DatasBean.YearsBean.ListBean bean);
    }

    OpenFinalItemClick openFinalItemClick;

    public void setOpenFinalItemClick(OpenFinalItemClick openFinalItemClick) {
        this.openFinalItemClick = openFinalItemClick;
    }
}
